package com.atguigu.blog.app;

import com.atguigu.blog.dto.response.Result;
import com.atguigu.blog.pojo.Article;
import com.atguigu.blog.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/article")
public class ArticleAppController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/findAll")
    public Result findAll() {
        List<Article> all = articleService.findAll();
        return Result.ok(all);
    }

    @GetMapping("/findById")
    public Result findById(String id) {
        Article article = articleService.findById(id);
        return Result.ok(article);
    }

}
